Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(icon-button): Add SVG support #3310

Merged
merged 8 commits into from
Aug 9, 2018

Conversation

williamernest
Copy link
Contributor

@williamernest williamernest commented Aug 7, 2018

fixes: #3277 , resolves #3154, resolves #3107
BREAKING CHANGE: Removes the previous data attributes and no longer dynamically changes the label. Allows developers to add both elements to the button, with one indicated as the on state by using a data-toggle-on attribute. State is now changed by adding/removing the mdc-icon-button--on class to the mdc-icon-button element. All icon elements should have the mdc-icon-button__icon class.

@mdc-web-bot
Copy link
Collaborator

🤖 Beep boop!

Screenshot test report 🚦

1 screenshot changed from master on commit fe86346:

Details

@codecov-io
Copy link

codecov-io commented Aug 7, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@a284aae). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3310   +/-   ##
=========================================
  Coverage          ?   98.06%           
=========================================
  Files             ?      120           
  Lines             ?     5155           
  Branches          ?      644           
=========================================
  Hits              ?     5055           
  Misses            ?      100           
  Partials          ?        0
Impacted Files Coverage Δ
packages/mdc-icon-button/constants.js 100% <ø> (ø)
packages/mdc-icon-button/foundation.js 100% <100%> (ø)
packages/mdc-icon-button/index.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a284aae...0d1146c. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

🤖 Beep boop!

Screenshot test report 🚦

1 screenshot changed from master on commit b18cfba:

Details

@mdc-web-bot
Copy link
Collaborator

🤖 Beep boop!

Screenshot test report 🚦

1 screenshot changed from master on commit ff8e432:

Details

demos/card.html Outdated
data-toggle-off-content="favorite_border"
data-toggle-off-label="Add to favorites">favorite_border</button>
title="Add to favorites" data-demo-toggle>
<i class="material-icons mdc-icon-button__icon" data-toggle-on>favorite</i>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we need to select on this data attribute in CSS, it might make sense to make it a class instead (e.g. mdc-icon-button__icon--on?) - attribute selectors perform a lot slower in IE and Edge.

Note the use of `data-toggle-on` attribute in the above examples. This attribute indicates which element is the
on element. When the `mdc-icon-button--on` class is present, the element with the `data-toggle-on` attribute
will be shown and the other element will be hidden. When the `mdc-icon-button--on` class is not present, the element
with the `data-toggle-on` attribute will be hidden and the other element will beshown. This is what allows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beshown -> be shown

on element. When the `mdc-icon-button--on` class is present, the element with the `data-toggle-on` attribute
will be shown and the other element will be hidden. When the `mdc-icon-button--on` class is not present, the element
with the `data-toggle-on` attribute will be hidden and the other element will beshown. This is what allows
MDCIconButtonToggle to be so flexible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is what allows MDCIconButtonToggle to be so flexible." -> "This structure allows MDCIconButton to be flexible enough to support both icon fonts and images/SVGs."

@@ -140,6 +157,7 @@ cannot be disabled. Disabled icon buttons cannot be interacted with and have no
CSS Class | Description
--- | ---
`mdc-icon-button` | Mandatory.
`mdc-icon-button--on` | Used to indicate the toggle button icon that is the not-selected option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't sound right... This class is applied to the root element when the toggle should be in the "on" state, right?

`addClass(className: string) => void` | Adds a class to the root element, or the inner icon element.
`removeClass(className: string) => void` | Removes a class from the root element, or the inner icon element.
`setText(text: string) => void` | Sets the text content of the root element, or the inner icon element.
`addClass(className: string) => void` | Adds a class to a icon element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these docs changed? Doesn't this still apply to the root element?

if (label) {
this.adapter_.setAttr(ARIA_LABEL, label);
}
this.adapter_.setAttr(strings.ARIA_PRESSED, `${this.isOn()}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.isOn() -> isOn?

if (classToRemove) {
this.adapter_.removeClass(classToRemove);
this.on_ = isOn;
if (this.isOn()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.isOn() -> isOn? We already have the variable right here.

@@ -157,7 +157,7 @@
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/07/31/04_55_54_478/spec/mdc-card/classes/baseline.html.windows_chrome_67.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/07/31/04_55_54_478/spec/mdc-card/classes/baseline.html.windows_edge_17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/07/31/04_55_54_478/spec/mdc-card/classes/baseline.html.windows_firefox_61.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/08/07/22_51_57_136/spec/mdc-card/classes/baseline.html.windows_firefox_61.png",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird...is this diff consistent, and if so do we have any possible explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's consistent. This was a result of me accepting screenshot diffs from master, not from within this branch.

@@ -22,6 +22,7 @@ import {verifyDefaultAdapter} from '../helpers/foundation';
import MDCIconButtonToggleFoundation from '../../../packages/mdc-icon-button/foundation';

const {strings} = MDCIconButtonToggleFoundation;
const {cssClasses} = MDCIconButtonToggleFoundation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change above line to const {cssClasses, strings} = ... and you don't need this line

});

test('#adapter.addClass adds a class to the inner icon element when used', () => {
const {root, component} = setupTest({useInnerIconElement: true});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to never use useInnerIconElement or tabIndex in setupTest anymore.

Are we losing anything by no longer supporting the inner icon element? I'm inclined to think that's mitigated by having separate DOM for each state now.

@mdc-web-bot
Copy link
Collaborator

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to have a foundation test for the isOn method.

DATA_TOGGLE_OFF_LABEL: 'data-toggle-off-label',
DATA_TOGGLE_OFF_CONTENT: 'data-toggle-off-content',
DATA_TOGGLE_OFF_CLASS: 'data-toggle-off-class',
DATA_TOGGLE_ON_ATTR: 'data-toggle-on',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer used since it's now a class

@@ -18,16 +18,12 @@
/** @enum {string} */
const cssClasses = {
ROOT: 'mdc-icon-button',
ICON_BUTTON_ON_CLASS: 'mdc-icon-button--on',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_CLASS seems redundant within the cssClasses hash... we could potentially even shorten this to just ON since it's a modifier class for the root element?

.mdc-icon-button__icon {
display: inline-block;

// stylelint-disable-next-line plugin/selector-bem-pattern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leaving a note here for posterity, that although this needs to do things that aren't entirely in line with BEM, we're significantly simplifying the JS implementation (including adapter) by toggling a single class on the root rather than needing to add a class to one child and remove it from the other every time the icon button is toggled.

<html lang="en">
<head>
<meta charset="utf-8">
<title>Baseline Icon Button - MDC Web Screenshot Test</title>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "Toggle" to this title

@mdc-web-bot
Copy link
Collaborator

@williamernest williamernest merged commit 25fa51e into master Aug 9, 2018
@williamernest williamernest deleted the feat/icon-button/svg-support branch August 9, 2018 21:09
@jamesmfriedman jamesmfriedman mentioned this pull request Aug 23, 2018
48 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants